//The cell class. Each cell needs a variety of things: It's position, whether it's a survival spot, and if it isn't, how many spots it does have.
#pragma once
#include "v2d.h"
#include "drawing.h"
#include "circle.h"
#include <stdio.h>
#define CIRCLE_SIZE			.05f
#define DOT_SIZE			.01f

class Cell
{
private:
	float x, y; //the cell's position.
	int xIndex, yIndex; //the cell's index in the map
	CircleF position; //used to check if mouse cursor is within the position.
	bool survival; //Whether it's a survival spot.
	int dots; //How many dots it has (For movement of the player class.)
	bool displayed; //True if circle will be displayed, false if its not displayed
	bool taken; //True if the cell already has a piece on it (how did we miss this!?)
	int level; //I would use the level from the map, but I'm not actually allowed to for some reason.
	bool nextMove;
public:
	Cell() {x = 0; y = 0; xIndex = 0; yIndex = 0; survival = false; dots = 1; position.set(V2DF(0,0), CIRCLE_SIZE); displayed = false; level = 1; nextMove = false;} //Basic constructor.
	Cell(float ex, float why, bool survive, int spots) {x = ex; y = why; survive = survival; dots = spots; position.set(V2DF(ex,why), CIRCLE_SIZE); displayed = false; xIndex = 0; yIndex = 0;} //The not so basic constructor.
	Cell(const Cell& c) {x = c.x; y = c.y; survival = c.survival; dots = c.dots; position.set(V2DF(c.x,c.y),CIRCLE_SIZE); displayed = c.displayed; xIndex = c.xIndex; yIndex = c.yIndex; nextMove = c.nextMove;} //Copy constructor.

	void setPos(float ex, float why) {x = ex, y = why, position.set(V2DF(ex,why),CIRCLE_SIZE);}
	bool getTaken() {return taken;}
	void take() {taken = true;}
	void unTake() {taken = false;} //This one should be different than the first one.
	float getX() {return x;}
	float getY() {return y;}
	void setSurvive(bool sur) {survival = sur;}
	bool getSurvive() {return survival;}
	void setDots(int spots) {dots = spots;}
	int getDots() {return dots;} //Those're the set and get functions.
	CircleF & getPosition() {return position;}
	bool drawned() {return displayed;}
	void setIndex(int ex, int why) { xIndex = ex; yIndex = why; }
	int getCol() { return xIndex; }
	int getRow() { return yIndex; }
	void next() {nextMove = !nextMove;}
	bool posNext() {return nextMove;}
	Cell & operator=(const Cell & rhs) 
	{
		x = rhs.x; 
		y = rhs.y; 
		survival = rhs.survival; 
		dots = rhs.dots; 
		position.set(V2DF(rhs.x,rhs.y),CIRCLE_SIZE); 
		displayed = rhs.displayed; 
		xIndex = rhs.xIndex; 
		yIndex = rhs.yIndex; 
		return *this;
	}
	void changeLevel(int cL) {level = cL;}

	void glDraw() //I know I shouldn't do this inside the header file, but I don't want to make a cpp solely for the glDraw.
	{
		displayed = true;
		switch(level)
		{
		case 1:
			glColor3ub(255, 200, 0);
			break;
		case 2:
			glColor3ub(55, 55, 255);
			break;
		case 3:
			glColor3ub(255, 55, 0);
			break;
		case 4:
			glColor3ub(255, 0, 255);
			break;
		}

		static int ignoreThis = 0;
		if(nextMove)
		{
			glColor3ub(255 - ignoreThis, 255-ignoreThis, 255-ignoreThis);
			ignoreThis += 10;
		} //Get rid of this later, after 3 player works, because a certain spot has a failing.
		glDrawCircle(x, y, CIRCLE_SIZE);		

		glColor3ub(255,255,255);
		switch(dots)
		{
		case 1:
			glDrawCircle(x, y, DOT_SIZE);
			glColor3ub(0,0,0);
			glDrawCircleOutline(x, y, DOT_SIZE);
			break;
		case 2:
			glDrawCircle(x-.01, y, DOT_SIZE);
			glDrawCircle(x+.01, y, DOT_SIZE);
			glColor3ub(0,0,0);
			glDrawCircleOutline(x-.01, y, DOT_SIZE);
			glDrawCircleOutline(x+.01, y, DOT_SIZE);
			break;
		case 3:
			glDrawCircle(x, y-.01, DOT_SIZE);
			glDrawCircle(x-.01, y+.01, DOT_SIZE);
			glDrawCircle(x+.01, y+.01, DOT_SIZE);
			glColor3ub(0,0,0);
			glDrawCircleOutline(x, y-.01, DOT_SIZE);
			glDrawCircleOutline(x-.01, y+.01, DOT_SIZE);
			glDrawCircleOutline(x+.01, y+.01, DOT_SIZE);
			break;
		case 4:
			glDrawCircle(x-.01, y-.01, DOT_SIZE);
			glDrawCircle(x+.01, y-.01, DOT_SIZE);
			glDrawCircle(x-.01, y+.01, DOT_SIZE);
			glDrawCircle(x+.01, y+.01, DOT_SIZE);
			glColor3ub(0,0,0);
			glDrawCircleOutline(x-.01, y-.01, DOT_SIZE);
			glDrawCircleOutline(x+.01, y-.01, DOT_SIZE);
			glDrawCircleOutline(x-.01, y+.01, DOT_SIZE);
			glDrawCircleOutline(x+.01, y+.01, DOT_SIZE);
			break;
		}
	}
	bool notNull() {if(x != 0 || y != 0) return true; else return false;} //Yes, I know that's bad.
};